package org.dandsoft.blackbox.laboratory.samples.lighter.view;

import org.dandsoft.blackbox.laboratory.samples.lighter.World;
import org.dandsoft.blackbox.laboratory.samples.lighter.Sun;
import org.dandsoft.blackbox.laboratory.samples.lighter.Body;
import org.dandsoft.blackbox.laboratory.tools.JCRMonitorStorage;
import org.dandsoft.blackbox.snn.Environment;
import org.dandsoft.blackbox.snn.Container;
import org.dandsoft.blackbox.snn.EnviromentTraceWriter;
import org.apache.commons.io.FileUtils;


import javax.swing.*;
import java.awt.*;
import java.io.File;

/**
 * Created by IntelliJ IDEA.
 * User: dvilyuzhanin
 * Date: 23.03.2009 19:53:24
 */
public class Frame extends JFrame {

    private int fieldWidth = 900;
    private int fieldHeight = 700;
    private World world;
    private WorldPanel worldPanel;
    private ToolPanel toolPanel;
    private LighterStatePanel lighterState;


    public Frame(World world) throws HeadlessException {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.world = world;
        setLayout(new BorderLayout());

        setSize(fieldWidth, fieldHeight);
        worldPanel = new WorldPanel(world);
        lighterState = new LighterStatePanel(world);
        toolPanel = new ToolPanel(lighterState, worldPanel, world);
        add(worldPanel, BorderLayout.CENTER);
        add(toolPanel, BorderLayout.NORTH);
        add(lighterState, BorderLayout.WEST);


        setVisible(true);

    }

    public void update() {

    }


    public static void main(String[] args) throws Exception {
        Sun sun = new Sun();
        sun.setCenterX(300);
        sun.setCenterY(200);
        sun.setX(100);
        sun.setY(200);
        sun.setSpeed(3.14 / 10);
        sun.setRange(200);
        File file = new File("e:/lighter");
        FileUtils.deleteDirectory(file);
        JCRMonitorStorage monitor = JCRMonitorStorage.createRepository(file.getAbsolutePath());
        Environment env = new Environment();
        env.setMonitor(monitor);
        env.setSequence(1);
        env.setTrace(new EnviromentTraceWriter(0, 1000, new File("e:/light.trace")));
        Container cont = new Container();
        Body body = new Body(env, cont);
        env.setSequence(30);
        World world = new World(body, 600, 600, sun);
        new Frame(world);
    }
}
